/*
 * KKSprite.h
 *
 *  Created on: 2013-9-15
 *      Author: wanghua
 */

#ifndef KKSPRITE_H_
#define KKSPRITE_H_

#include "kaka_common.h"
#include "KKClipableNode.h"
#include "KKSpriteAnimation.h"
#include "KKGestureDirector.h"
#include "XmlUtils.h"
#include "Box2D/Box2D.h"

using namespace std;

USING_NS_CC;

typedef KKDictionary<string, KKSpriteAnimation*> KKSpriteAnimationDictionary;

class KKSprite: public CCSprite, public KKClipableNode {

private:

	;CC_SYNTHESIZE_READONLY(string,m_currentAnimationName,CurrentAnimationName)
	;CC_SYNTHESIZE(KKSpriteAnimationDictionary*,m_animations,Animations)

	;

public:
	static const int ANIMATION_TAG = 10000;
	static const int STORYBOARD_TAG = 10001;

protected:

	KKSprite();
public:

	virtual ~KKSprite();

	virtual void animate(float duration, const char* frameNames, ...);

	virtual void animate(const char* animName, int loop = 0, bool fill = false,
			CCObject* endTarget = NULL, SEL_CallFuncND endFunc = NULL,
			void* args = NULL, float delay = 0);

	virtual CCAnimate* getAnimation(const char* animName, bool fill = false);

	void setDisplayFrame(CCSpriteFrame *pNewFrame);

	void setTextureFile(string pszFileName, bool assignImage = true,
			bool keepsize = false);

	void resetTexture();

	static KKSprite* spriteWithFile(const char *pszFileName);

	static KKSprite* spriteWithTexture(CCTexture2D* texture);

	KKNODE_FACTORY_METHOD(KKSprite,spriteWithXml)
	;

	virtual void saveToXml(TiXmlElement* element);

	virtual bool initCommonInfoWithXml(TiXmlElement* element, KKNode* parent);

	virtual bool initDelayInfoWithXml(TiXmlElement* element);

	virtual void setOpacity(GLubyte opacity);

	virtual void setIsVisible(bool isVisible);

	virtual void onEnter();

	virtual void onExit();

	virtual bool getIsVisible() {
		return CCSprite::isVisible();
	}
	;

	virtual void onDown(const KKTouch& touch);
	virtual void onUp(const KKTouch& touch);

	virtual void setSelected(bool selected);

	virtual void setIsEnable(bool enabled);

	virtual void visit();

};

KKNODE_PARSER_CLASS(KKSpriteParser,KKSprite,spriteWithXml)
;
#endif /* KKSPRITE_H_ */
